package com.yoomiito.app.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.yoomiito.app.R;
import com.yoomiito.app.base.App;
import com.yoomiito.app.utils.ResUtil;

import cn.droidlover.xdroidmvp.log.XLog;

public class DeleteCarDialog extends Dialog implements View.OnClickListener {


    Button cancel;
    //    @BindView(R.id.confirm)
    Button confirm;

    private Context mContext;
    private OnCloseListener mOnCloseListener;

    private int size = -1;
    private int color = -1;

    private TextView tv;

    public DeleteCarDialog(@NonNull Context context, OnCloseListener onCloseListener) {
        super(context, R.style.dialog);
        mContext = context;
        mOnCloseListener = onCloseListener;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_delete_car, null);

        tv = view.findViewById(R.id.tv_content);
        view.findViewById(R.id.cancel).setOnClickListener(this);
        view.findViewById(R.id.confirm).setOnClickListener(this);
        setContentView(view);
        setCanceledOnTouchOutside(false);

        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = (int) (App.mWidthPx * 0.8);
        getWindow().setAttributes(lp);

    }

    @Override
    protected void onStart() {
        super.onStart();

    }


    public void setContent(String content) {
        if (tv != null)
            tv.setText(content);
    }


    public void setContentSize(int size) {
        this.size = size;
    }

    public void setContentColor(int color) {
        this.color = ResUtil.getColor(color);
    }


//    @OnClick({R.id.cancel, R.id.confirm})
//    @Override
//    public void onViewClicked(View view) {
//
//    }

    @Override
    protected void onStop() {
        super.onStop();
//        ub.unbind();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.cancel:

                dismiss();
                break;
            case R.id.confirm:
                if (mOnCloseListener != null) {
                    mOnCloseListener.confirm();
                } else {
                    XLog.e("Dialog", "没有设置mOnCloseListener");
                }
                dismiss();
                break;
        }
    }

    public interface OnCloseListener {
        void confirm();
    }
}
